<?php
class SettingController extends AppController {

    /**
     * 
     */
    public function index(){
        $this->loadModel('Setting');
        $data = $this->Setting->find('all');
        $this->set('data',$data);
    }

    /**
     * 
     */
    public function edit($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid Setting'));
        }

        $Setting = $this->Setting->find('first', array('conditions' => array('Setting.Id' => $id)));
        if (!$Setting) {
            throw new NotFoundException(__('Invalid Setting'));
        }

        if ($this->request->is(array('post', 'put'))) {
            $this->Setting->id = $id;
            if($id == 1){
                $this->Setting->setValidateTimePing();
            }
            if($id == 2){
                $this->Setting->setValidateEmail();
            }
            if ($this->Setting->save($this->request->data)) {
                $this->Session->setFlash(__('Your Setting has been updated.'));
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash(__('Unable to update your Setting.'));
        }

        if (!$this->request->data) {
            $this->request->data = $Setting;
        }
        $this->set('id',$id);
    }
}
